<template>
  <view class="webview-container">
    <!--    #ifdef APP-PLUS||H5-->
    <navbar :title="title"></navbar>
    <!-- #endif -->

    <!-- #ifndef APP-PLUS -->
    <web-view :src="url" :style="'top:'+top+'px'"></web-view>
    <!-- #endif -->
  </view>
</template>

<script>
import appConfig from '@/appConfig'
import navbar from '@/components/navbar'
import {
  mapGetters
} from 'vuex'

export default {
  components: {
    navbar
  },
  data() {
    return {
      title: '',
      url: '',
      top: 0
    }
  },
  computed: {
    ...mapGetters(['systemInfo'])
  },
  onLoad({url, type, title}) {
    this.top = this.systemInfo.statusBarHeight + 44

    if (type === 'yinsi') {
      this.title = '隐私政策'
      this.url = appConfig.host + appConfig.h5.yinsi
    } else if (type === 'yonghu') {
      this.title = '用户协议'
      this.url = appConfig.host + appConfig.h5.yonghu
    } else if (type === 'geren') {
      this.title = '个人信息收集清单'
      this.url = appConfig.host + appConfig.h5.geren
    } else if (type === 'sanfang') {
      this.title = '第三方信息共享清单'
      this.url = appConfig.host + appConfig.h5.sanfang
    } else if (type === 'vip') {
      this.title = '驾考会员协议'
      this.url = appConfig.host + appConfig.h5.vip
    } else if (type === 'pdf') {
      this.url = decodeURIComponent('https://api.jiakao.qwdata.vip/public/web/viewer.html?file=' + url)
      this.title = title
    } else {
      this.url = decodeURIComponent(url)
      this.title = title
    }

    this.url = this.url.replace('#appId#', this.systemInfo.packageName)

    console.log(this.url)


    // #ifdef APP-PLUS
    let wv = plus.webview.create("", "custom-webview", {
      plusrequire: "none", //禁止远程网页使用plus的API，有些使用mui制作的网页可能会监听plus.key，造成关闭页面混乱，可以通过这种方式禁止
      'uni-app': 'none', //不加载uni-app渲染层框架，避免样式冲突
      top: this.top, //放置在titleNView下方。如果还想在webview上方加个地址栏的什么的，可以继续降低TOP值
      bottom: 0
    })
    wv.loadURL(this.url)
    var currentWebview = this.$scope
        .$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效
    currentWebview.append(wv); //一定要append到当前的页面里！！！才能跟随当前页面一起做动画，一起关闭
    // #endif
  },

  onReady() {

  },

  methods: {
    toBack() {
      uni.navigateBack()
    },
  }
}
</script>

<style lang="scss">
.webview-container {
  display: flex;
  flex-direction: column;
}
</style>
